<form name="form1" method="post">
<table width="600" border="0">
  <tr>
	<td>Tipo:</td>
		<td>
		<SELECT NAME="tipo" id="tipo" onChange="CambiaTipo();">
			<OPTION value="O" selected="selected" <?=($objeto->tipo=="O") ? "selected" : "" ?>>POR OFICINA
			<OPTION value="P" <?=($objeto->tipo=="P") ? "selected" : "" ?>>POR PERITO
		</SELECT>
		</td>
  </tr>
  
  <tr>
    <td >Oficina:</td>
    <td ><?=helpers::combo($conn, '', empty($objeto->id_zona) ? "-1" :$objeto->id_zona ,'','','id_zona','id','nombre','id_zona','',"SELECT * FROM zonas WHERE id = ". $_SESSION['SesionZona'] . " OR id IN (SELECT id FROM zonas WHERE id_padre =" . $_SESSION['SesionZona'] . ") ORDER BY nombre","CargaUsuarios();","1")?></td>
  </tr>

  <tr id="trPeritos" <?=($objeto->tipo=="O" || empty($objeto->tipo)) ? "style='display:none'" : "" ?>>
    <td width="100">Perito:</td>
		<td colspan="3" ><?=helpers::combo($conn, '', (!empty($objeto->id_perito)) ? $objeto->id_perito : "-1",'','','id_perito','id','nombre','id_perito','',!empty($objeto->id_zona) ? "SELECT * FROM peritos WHERE id_zona = " . $objeto->id_zona. " AND estatus='A' ORDER BY nombre" : "SELECT * FROM peritos WHERE estatus='A' ORDER BY nombre",'','1')?></td>		
    </td>
  </tr>

<tr id="Fecha">
	<td>Fecha:</td>
	<td >
		<table>
			<tr>
				<td><input value="<?=empty($objeto->fecha) ? date("d/m/Y") : muestrafecha($objeto->fecha)?>" name="fecha" id="fecha"  type="text" style="width:80px" /></td> 
				<td > 
					<a href="#" id="boton_fecha" onclick="return false;"><img border="0" src="images/calendarA.png" width="20" height="20" /></a>  
					<script type="text/javascript">
						new Zapatec.Calendar.setup({
								firstDay          : 1,
								weekNumbers       : true,
								showOthers        : false,
								showsTime         : false,
								timeFormat        : "24",
								step              : 2,
								range             : [1900.01, 2999.12],
								electric          : false,
								singleClick       : true,
								inputField        : "fecha",
								button            : "boton_fecha",
								ifFormat          : "%d/%m/%Y",
								daFormat          : "%Y/%m/%d",
								align             : "Br"
							});
					</script>
				</td>
			</tr>
		</table>
	</td>
</tr>

<tr>
	<td>Observaciones:</td>
	<td colspan="2">
		<textarea name="observaciones" id="observaciones" rows="3" cols="44" ><?=$objeto->observaciones?></textarea>
	</td>
</tr>


<tr>
	<td colspan="2"><hr /><span class="titulo">Rango Del Material</span></td>
</tr>

  <tr>
    <td width="100">Tipo Experticia:</td>
		<td colspan="2" ><?=helpers::combo($conn, '', $objeto->id_tipo,'','','id_tipo','id','nombre','id_tipo','','SELECT * FROM tipos_experticia ORDER BY nombre','','1')?></td>
   </td>
  </tr>

  <tr>
    <td width="100px">Desde:</td>
    <td>
		<input type="text" name="desde" id="desde" style="width:100px" value="<?=$objeto->desde?>">
	</td>
  </tr>

  <tr>
    <td>Hasta:</td>
    <td>
		<input type="text" name="hasta" id="hasta" onChange="ValidaNumeros();" style="width:100px" value="<?=$objeto->hasta?>">
	</td>
  </tr>

<tr>
	<td align="left" colspan="2"  ><input type="button" value="Agregar" onClick="Agregar()"></td>
	<td align="right" colspan="2"  ><input type="button" value="Eliminar" onClick="Eliminar()"></td>
</tr>
	
<tr>
	<td colspan="4"><div id="gridbox" width="500" height="150" class="gridbox"></div></td>
</tr>


</table>

<input style="float:right"  name="accion" type="button" value="<?=$boton?>" onclick="Guardar();<?=$validator->validate() ?>" />
<input name="id" type="hidden" value="<?=$objeto->id?>" />
<input name="accion" type="hidden" value="<?=$boton?>" /> 
<input name="limites" id="limites" type="hidden" value="" />
<span style="position:absolute;top:4px;right:5px;cursor:pointer;">
<img onclick="close_div();" src="images/close_div.gif" /></span>
</form>
<p class="errormsg">(*) Campo Requerido</p

<script type="text/javascript">
buildGrid();
CargarGrid();
function buildGrid(){
	//set grid parameters
	mygrid = new dhtmlXGridObject('gridbox');
	mygrid.selMultiRows = true;
	mygrid.setImagePath("js/grid/imgs/");
	mygrid.setHeader("Id,Tipo,Desde, Hasta");
	mygrid.setInitWidths("50,200,125,125");
	mygrid.setColAlign("left,left,right,right");
	mygrid.setColTypes("ro,ro,ro,ro");
	mygrid.setColSorting("str,str,int,int");
	mygrid.setColumnColor("white,white,white, white");
	mygrid.rowsBufferOutSize = 0;
	mygrid.setMultiLine(false);
	mygrid.selmultirows="true";
	mygrid.delim=";";
	//start grid
	 mygrid.enableLightMouseNavigation(true); mygrid.init();
} 

function CargarGrid(){
var JsonAux;
	mygrid.clearSelection();
	mygrid.clearAll();
	if("<?=$objeto->id?>"){ 
		if('<?=$objeto->limites?>'){
			var Limites = eval( '(' + '<?=$objeto->limites?>' + ')');
			for(i=0;i<Limites.length;i++){
				mygrid.addRow(i,Limites[i][0]+";"+Limites[i][1]+";"+muestraFloat(parseFloat(Limites[i][2]),2)+";"+muestraFloat(parseFloat(Limites[i][3]),2),i);
			}
		}
	}
}
</script>

